package aiku.numericalcontroloa.Service.productType;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import aiku.numericalcontroloa.Base.Utils.Result;
import aiku.numericalcontroloa.Mapper.productType.productlibraryMapper;
import aiku.numericalcontroloa.Model.Entity.productType.productlibrary;

@Service
public class productlibraryServiceImpl implements productlibraryService {

    @Autowired
    private productlibraryMapper mapper;

    @Override
    public Result getProductlibrary() {
        List<productlibrary> list = mapper.selectList(null);
        return Result.success("查询完成", list);
    }

    @Override
    public Result addProductlibrary(productlibrary data) {
        if (data == null && data.getProducttype() == null && data.getLibraryName() == null
                && data.getProducttype() == "" && data.getLibraryName() == "") {
            return Result.error("参数为空");
        }
        data.setDeleted(0);
        data.setId(null);
        if (mapper.insert(data) == 1) {
            return Result.success("添加成功");
        } else {
            return Result.error("添加失败");
        }
    }

    @Override
    public Result updateProductlibrary(productlibrary data) {
        if (data == null && data.getLibraryName() == null && data.getLibraryName() == "") {
            return Result.error("参数为空");
        }
        if (mapper.updateById(data) == 1) {
            return Result.success("修改成功");
        } else {
            return Result.error("修改失败");
        }
    }

    @Override
    public Result deleteProductlibrary(productlibrary data) {
        if (data == null) {
            return Result.error("参数为空");
        }
        data.setDeleted(1);
        if (mapper.deleteById(data) == 1) {
            return Result.success("删除成功");
        } else {
            return Result.error("删除失败");
        }
    }

}
